home *** CD-ROM | disk | FTP | other *** search
/ Night Owl 6 / Night Owl's Shareware - PDSI-006 - Night Owl Corp (1990).iso / 036a / pmfinder.zip / ARC.C next >
Text File  |  1991-12-05  |  3KB  |  114 lines

  1. #include <os2.h>
  2. #include <stdio.h>
  3. #include <stdlib.h>
  4. #include <string.h>
  5. #include <io.h>         /* needed for open, close, read, write, */
  6.                         /* filelength, and eof */
  7. #include <fcntl.h>      /* needed for open mode arguments */
  8. #include <sys\types.h>  /* needed for file types */
  9. #include <sys\stat.h>   /* needed for status flags */
  10. #include <malloc.h>     /* needed for _memmax, malloc. and free */
  11.  
  12. #include "archive.h"
  13. #include "arc.h"
  14.  
  15. extern BOOL pascal fContinue;
  16. /*
  17.     This module performs the ARC and PAK file search.
  18.     These functions have changed slightly from
  19.     Don A. Williams orginal code.
  20.     I've removed references to global variables.
  21.  *
  22.  */
  23.  
  24. /***********************************************************************
  25.  * DoArc is the main routine to process an entire Arc file             *
  26.  ***********************************************************************/
  27.  
  28.  void
  29. DoArc (char *Pattern,char *Path,HWND hwndListBox)
  30. {
  31.    FILE *ArcFile;
  32.    ARCHIVE_HEADER ArchiveHead;
  33.    char szListBox[260];
  34.    char V_Name[14], V_Path[65];
  35.    int Status;
  36.  
  37.    if ( (ArcFile = fopen(Path, "rb")) == NULL )
  38.    {
  39.       strcpy(szListBox,
  40.              "ArcFile Error - Unable to open - ");
  41.       strcat(szListBox,Path);
  42.       AddToListBox(hwndListBox,szListBox);
  43.    }
  44.    else
  45.    {
  46.       while ( (Status = GetEntryArc(ArcFile, &ArchiveHead)) != 0 && fContinue )
  47.       {
  48.          if (Status < 0)
  49.          {
  50.             if (Status == -1)
  51.             {
  52.                strcpy(szListBox,
  53.                       "ArcFile Error - Unable to read header - ");
  54.                strcat(szListBox,Path);
  55.                AddToListBox(hwndListBox,szListBox);
  56.                break;
  57.             }
  58.             else
  59.             {
  60.                if (Status == -2)
  61.                {
  62.                   strcpy(szListBox,
  63.                          "ArcFile Error - Invalid ArcMark - ");
  64.                   strcat(szListBox,Path);
  65.                   AddToListBox(hwndListBox,szListBox);
  66.                   break;
  67.                }
  68.                else
  69.                {
  70.                   strcpy(szListBox,
  71.                          "ArcFile Error - Unknown error - ");
  72.                   strcat(szListBox,Path);
  73.                   AddToListBox(hwndListBox,szListBox);
  74.                   break;
  75.                }
  76.             }
  77.          }
  78.          else
  79.          {
  80.             if ( Match(ArchiveHead.Name,Pattern) )
  81.             {
  82.                strcpy(V_Name, ArchiveHead.Name);
  83.                strcpy(V_Path, Path);
  84.                sprintf(szListBox,"%s--> (%s)", V_Path, V_Name);
  85.                AddToListBox(hwndListBox,szListBox);
  86.             }
  87.          }
  88.       }
  89.       fclose(ArcFile);
  90.    }
  91. }
  92. /***********************************************************************
  93.  * GetEntryArc will read and verify the next entry in the distributed     *
  94.  * directory of an ARC or PAK file.                                    *
  95.  ***********************************************************************/
  96.  
  97.  static int
  98. GetEntryArc (FILE *ArcFile, ARCHIVE_HEADER *ArchiveDir)
  99. {
  100.  
  101.    if (fread(ArchiveDir, sizeof(char), sizeof(ARCHIVE_HEADER), ArcFile) < 2)
  102.    {
  103.       return(-1);
  104.    }
  105.    if (ArchiveDir->ArcMark != 0x1A)
  106.    {
  107.       return(-2);
  108.    }
  109.    if (ArchiveDir->HeaderVersion == 0) return(0);
  110.  
  111.    fseek(ArcFile, ArchiveDir->Size, SEEK_CUR);
  112.    return(1);
  113. }
  114.